# -*- conding:utf-8 -*-

"""
@author: PoXiao
@file: GA_main.py
@time: 2019/3/23 0023 16:56

"""
from traffic_fitness import *
from creat_crossMap import *
from creat_roadMap import *
import scipy.io
data1 = scipy.io.loadmat('map8.mat')
data2 = scipy.io.loadmat('pop8.mat')
road = data1['road']
car = data1['car']
cross = data1['cross']
pop = data2['pop']
chromosome = pop[2,:]
crossMap = creat_crossMap(cross)
crossMap = np.array(crossMap, dtype=np.int)
road = creat_roadMap(road, crossMap)
road = np.array(road, dtype=np.int)
# 生成所有车辆的导航
chromosome = np.zeros((car.shape[0], cross.shape[0]), int)
# 把车辆编号和出发时间编入 allChromosome
chromosome = np.concatenate((car[:, 0:2], chromosome), axis=1)
# 起始点标记
for i in range(car.shape[0]):
    # 获得对应车的起始点
    startPoint = car[i][1]
    chromosome[i][startPoint+1] = 1
# allChromosome = allChromosome.flatten()
chromosome = pop[2,:]
fitness = traffic_fitness(chromosome, road, car, cross, crossMap)
print(fitness)

